

export default class ApiRadio{
    // noinspection JSAnnotator
    constructor(element, option) {
        this.$element = $(element);
        this.$radio = this.$element.find('input[type="radio"]');
        this.init();
    }

    init() {
        if (this.$radio.prop('checked')) {
            this.$element.addClass('checked')
        }

        this.$radio.on('change', (e) => {
            e.stopPropagation();
            this.toggleChecked(e);
        })
    }

    get radioValue(){
        if(this.$radio.prop('checked')){
            return this.$radio.val();
        }
        return null;
    }
    set radioValue(value){
    }

    toggleChecked() {
        const isChecked = this.$radio.prop('checked');
        if(isChecked){
            this.$element.addClass('checked').siblings().removeClass('checked');
            this.radioValue = this.$element.val();
        }
    }
}